using System.Collections.Generic;
using Magiq.Providers.Entities.Query;
using Magiq.Support;
using MirrorMirror;

namespace Magiq.Providers.Entities.Insert
{
    public class CollectionInsertDestination<TDestination, TNew> : IInsertDestination<TNew>
        where TDestination : class
        where TNew : class, TDestination, new()
    {
        private readonly IList<TDestination> list;

        public CollectionInsertDestination(IMagiqToEntitiesCollectionQueryable collection)
        {
            list = collection.Item.Get<IList<TDestination>>(collection.Member.Name);
        }

        #region IInsertDestination<TNew> Members

        public void Insert(IEnumerable<TNew> items)
        {
            foreach (var item in items)
                list.Add(item);
        }

        #endregion
    }
}